<%@ page pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:set var="path" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<base href="${path}/page/seat/">
	<title>座位列表</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="${path}/layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="${path}/css/public.css" media="all" />
	<link rel="stylesheet" href="${path}/css/my.css" media="all" />
</head>

<body>
	<div class="layui-fluid">
		<div class="layui-card">
			<!-- 搜索栏 -->
			<div id="search-form" class="layui-form layui-card-header layuiadmin-card-header-auto">
				<div class="layui-form-pane">
					<div class="layui-form-item">
						<label class="layui-form-label" style="width: 100px;">校区</label>
						<div class="layui-input-inline" style="width: 130px;">
							<input type="text" name="campus" class="layui-input" placeholder="输入校区" />
						</div>						
						<div class="layui-input-inline">
							<div class="layui-btn-group">
								<button class="layui-btn" lay-submit lay-filter="LAY-search">
	            					<i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>查询
	          					</button>
								<button class="layui-btn layui-btn-warm" id="LAY-reset" lay-filter="LAY-reset">
	            					<i class="layui-icon layui-icon-close layuiadmin-button-btn"></i>清除
	          					</button>
							</div>
						</div>
					</div>
				</div>
			</div>			
			<!-- 表格 -->
			<div class="layui-card-body">
				<div style="padding-bottom:10px">
					<div class="layui-btn-group">
						<button class="layui-btn layui-btn-normal layui-btn-list" data-type="add"><i class="layui-icon layui-icon-add-1"></i> 添加</button>
						<button class="layui-btn layui-btn-danger layui-btn-list" data-type="batchdel"><i class="layui-icon layui-icon-delete"></i> 删除</button>
					</div>
				</div>
				<table id="LAY-table" lay-filter="LAY-table"></table>
			</div>
		</div>
	</div>	

	<!-- 自定义模板 -->
  	<script type="text/html" id="tbar">
    	<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
  	</script>
  	
  	<script type="text/javascript" src="${path}/js/jquery-1.11.3.min.js"></script>
  	<script type="text/javascript" src="${path}/layui/layui.js"></script>
  	<script type="text/javascript" src="${path}/js/commons.js"></script>
  	
  	<script>
  	layui.use(['table'], function(){  		
    	var table = layui.table;
    	var form = layui.form;
    	var $ = layui.jquery;
    	
      	//座位列表
        var tbconfig = $.extend($$.tbconfig, {
            url : '${path}/action/seat/list',
            cols : [[
            	{checkbox: true},
    			{title: '#', type:'numbers', align: 'center', width: 40},
                {field: 'campus', title: '校区', sort:true},	
                {field: 'floor', title: '楼层'},
                {field: 'classroom', title: '教室'},
                {field: 'num', title: '座位号'},                
                {field: 'status', title: '状态', templet: function(d) {
                	if(d.status == 0) return '<span class="layui-red">空</span>';
                	if(d.status == 1) return '<span class="layui-blue">已占</span>';
                }},
                {field: 'name', title: '使用者'},
                {field: 'ctime', title: '开始时间'},
                {field: 'endtime', title: '离开时间'},
                {title: '操作', width:170, templet:'#tbar',fixed:"right"}
            ]]             
        });
        table.render(tbconfig);
      	
     	// 排序
        table.on('sort(LAY-table)', function(obj) {
        	table.reload('LAY-table', {
        		initSort: obj,
        		where: obj
        	})
        });
    	//监听搜索
    	form.on('submit(LAY-search)', function(data) {
      		var field = data.field;      
      		//执行重载
      		table.reload('LAY-table', {
        		where: field,
        		page: {curr: 1}
      		});
    	});
    	//重置
    	$('#LAY-reset').click(function() {
    		$('#search-form :input').val('');
    	});
     	// 工具栏
        table.on('tool(LAY-table)', function(obj) {
            var data = obj.data;
            if(obj.event === 'del') {
                layer.confirm('您确定要删除行吗？', function(index) {
                	$$.ajax({
        				url: '${path}/action/seat/multiDel',
        				data: {
        					ids: data.id
        				},
        				success: function(json) {
        					table.reload('LAY-table');
                  			layer.msg('删除成功！');	
        				}        				
        			});
                })
            } else if(obj.event === 'edit') {
            	layer.open({
	          		type: 2,
	          		title: '编辑座位',
	          		content: '${path}/action/seat/get?id=' + data.id,
	          		maxmin: true,
	          		area: ['450px', '530px'],
	          		btn: ['确定', '取消'],
	          		yes: function(index, layero){
	            		var submit = layero.find('iframe').contents().find("#LAY-form-submit");
	            		submit.click();
	          		}
	        	}); 
            }
        });    	
    	
    	// toolbar工具栏
    	var active = {
      		batchdel: function() {
        		var checkData = table.checkStatus('LAY-table').data; //得到选中的数据
        		if(checkData.length === 0) {
        			layer.msg('请选择数据');
          			return false;
        		}
        			
        		var idArr = [];
        		for(var i=0; i<checkData.length; i++) {
        			idArr.push(checkData[i].id);
        		}
        		layer.confirm('确定删除吗？', function(index) {
        			$$.ajax({
        				url: '${path}/action/seat/multiDel',
        				data: {
        					ids: idArr.join(',')
        				},
        				success: function(json) {
        					table.reload('LAY-table');
                  			layer.msg('已删除');	
        				}        				
        			});          			
        		});
      		},
	      	add: function() {
	        	layer.open({
	          		type: 2,
	          		title: '增加座位',
	          		content: 'seat_form.jsp',
	          		maxmin: true,
	          		area: ['450px', '330px'],
	          		btn: ['确定', '取消'],
	          		yes: function(index, layero){
	            		//点击确认触发 iframe 内容中的按钮提交
	            		var submit = layero.find('iframe').contents().find("#LAY-form-submit");
	            		submit.click();
	          		}
	        	}); 
      		}      		
   		}; 

		$('.layui-btn.layui-btn-list').on('click', function(){
      		var type = $(this).data('type');
      		active[type] ? active[type].call(this) : '';
		});

  	});
  </script>
</body>

</body>
</html>